package cn.schoolwow.quickdao.module.database.dml.instance.service.insert;

import cn.schoolwow.quickdao.module.database.dml.existQuery.service.GetInstanceCountFlow;
import cn.schoolwow.quickflow.domain.FlowContext;
import cn.schoolwow.quickflow.flow.BusinessFlow;

public class InsertIgnoreInstanceFlow implements BusinessFlow {
    @Override
    public void executeBusinessFlow(FlowContext flowContext) throws Exception {
        flowContext.executeFlowList(new GetInstanceCountFlow());
        Long count = flowContext.checkData("count", Long.class);
        if(count>0){
            flowContext.putData("effect", 0);
            flowContext.broken("实例已经存在于数据库");
        }else{
            flowContext.executeCompositeFlowList(new InsertInstanceCompositeBusiness());
        }
    }

    @Override
    public String name() {
        return "忽略插入实例";
    }

}